package com.example.geange.demo01;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class News extends Fragment implements OnItemClickListener{



    public static List<NewsItem> listNews = new ArrayList<>();
    public static NewsAdapter newsAdapter;
    private ListView listView;
    LinearLayout liny;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_news, container, false);
//        liny = (LinearLayout) view.findViewById(R.id.frame);
        listView = (ListView) view.findViewById(R.id.news_list);
        newsAdapter = new NewsAdapter(listNews, getActivity());
        listView.setAdapter(newsAdapter);
        listView.setOnItemClickListener(this);
        return view;
    }



    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        webview_news wn = new webview_news(listNews.get(i).getContent());

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame, wn);
        fragmentTransaction.commit();
        Toast.makeText(getActivity(), listNews.get(i).getContent(), Toast.LENGTH_SHORT).show();
    }
}
